AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
--include('entities/base_wire_entity/init.lua')
include( 'shared.lua' )
util.PrecacheSound( "SB/Gattling2.wav" )

function ENT:Initialize()

	self.Entity:SetModel( "models/Slyfo/rover_snipercannon.mdl" ) 
	self.Entity:SetName("Small Sniper")
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )

	if WireAddon then
		self.Inputs = WireLib.CreateInputs( self, { "Fire", "FireType" } )
	end

	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableGravity(true)
		phys:EnableDrag(true)
		phys:EnableCollisions(true)
	end
	self.Entity:SetKeyValue("rendercolor", "255 255 255")
	self.PhysObj = self.Entity:GetPhysicsObject()
end

function ENT:SpawnFunction( ply, tr )

	if ( !tr.Hit ) then return end
	
	local SpawnPos = tr.HitPos + tr.HitNormal * 16 + Vector(0,0,50)
	
	local ent = ents.Create( "weapon_SmallSniper" )
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	ent.SPL = ply
	ent.FireMode = 1
	return ent
	
end

function ENT:TriggerInput(iname, value)		
	if (iname == "Fire") then
		if (value > 0) then
			self.Active = true
		else
			self.Active = false
		end
	elseif iname == "FireType" then
		if (value > 1) then
			self.FireMode = value
		else
			self.Firemode = 1
		end
	end
end

function ENT:PhysicsUpdate()

end

function ENT:Think()
	local RTime = 1
	if (self.Active == true or self.FTime > CurTime() ) then
		local ammo = self:GetResourceAmount("Ammo")
		local exp = self:GetResourceAmount("Ammo Exp")		
		if ammo>=4 and self.FireMode == 1 then
			self:ConsumeResource("Ammo", 4)
			self:MakeBullet(30,0,0.01,10,1)
			local effectdata = EffectData()
				effectdata:SetOrigin(self:GetPos() + self:GetForward() * 18)
				effectdata:SetAngle(self:GetAngles())
				effectdata:SetScale( 1.5 )
			util.Effect( "MuzzleEffect", effectdata )
			self.Entity:EmitSound("SB/Gattling2.wav", 400)
			RTime = 2
		elseif exp >= 8 then
			self:ConsumeResource("Ammo Exp", 8)
			self:MakeBullet(40,1,0.02,10,1)
			local effectdata = EffectData()
				effectdata:SetOrigin(self:GetPos() + self:GetForward() * 18)
				effectdata:SetAngle(self:GetAngles())
				effectdata:SetScale( 1.5 )
			util.Effect( "MuzzleEffect", effectdata )
			self.Entity:EmitSound("SB/Gattling2.wav", 400)
			RTime = 4
		end
	end
	self.Entity:NextThink( CurTime() + 2 )
	return true
end

function ENT:PhysicsCollide( data, physobj )
	
end

function ENT:OnTakeDamage( dmginfo )
	
end

function ENT:Use( activator, caller )

end

function ENT:HPFire()
	self.FTime = CurTime() + 0.1
end